package com.pcbly.web.persistence.workflow;

import java.util.List;

import org.hibernate.Query;

import com.pcbly.web.bean.workflow.WorkflowCustomerBean;
import com.pcbly.web.persistence.HibernateBaseDao;

@SuppressWarnings("unchecked")
public class WorkflowCustomerHibernateDao extends
		HibernateBaseDao<WorkflowCustomerBean> implements WorkflowCustomerDao {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7600236670790132983L;

	public WorkflowCustomerHibernateDao() {
		super();
	}

	protected Class<WorkflowCustomerBean> getEntityClass() {
		return WorkflowCustomerBean.class;
	}

	@Override
	public void createWorkflowCustomerBean(WorkflowCustomerBean bean)
			throws Exception {
		// TODO Auto-generated method stub
		getHibernateTemplate().save(bean);
	}

	@Override
	public void delectWorkflowCustomersByColumnNameAndValue(String columnName,
			String columnValue) throws Exception {
		// TODO Auto-generated method stub
		StringBuilder sb=new StringBuilder();
		sb.append("delete WorkflowCustomerBean a where a.");
		sb.append(columnName);
		sb.append("=?"); 
		Query query=getSession().createQuery(sb.toString());
		query.setString(0, columnValue).executeUpdate();
	}

	
	@Override
	public List<WorkflowCustomerBean> findWorkflowCustomersByColumnNameAndValue(
			String columnName, String columnValue) throws Exception {
		// TODO Auto-generated method stub
		StringBuilder sb=new StringBuilder();
		sb.append("select a WorkflowCustomerBean a where a.");
		sb.append(columnName);
		sb.append("=?"); 
		Query query=getSession().createQuery(sb.toString());
		List list=query.setString(0, columnValue).list();
		return list;
	}
}
